<?php
class ModelTotalSlippers extends Model {
	public function getTotal(&$total_data, &$total, &$taxes) {

		if(time()>strtotime('2017-10-01 00:00:00') && time()<strtotime('2017-11-30 23:59:59')){

			$temp_total = $this->cart->getTotal();

			$price = 0;

			$quantity = 0;

			$reduce_total = 0;

			if($this->cart->hasProducts()){

				foreach($this->cart->getProducts() as $val){

					if($val['option'][0]['product_code'] == '33020400010'){

						$temp_total -= $val['total'];

						$price = $val['price'];

						$quantity = $val['quantity'];

						break;

					}

				}

				if($temp_total >= 3000 && $temp_total < 5000){

					if($quantity <= 240 && $quantity > 0){

						$price -= 5.9;

						$price = $price < 0?0:$price;

						$reduce_total = $quantity * $price;

						$total -= $reduce_total;

					}elseif($quantity > 240){

						$price -= 5.9;

						$price = $price < 0?0:$price;

						$reduce_total = 240 * $price;

						$total -= $reduce_total;

					}

				}elseif($temp_total >= 5000 && $temp_total < 10000){

					if($quantity <= 480 && $quantity > 0){

						$price -= 5.9;

						$price = $price < 0?0:$price;

						$reduce_total = $quantity * $price;

						$total -= $reduce_total;

					}elseif($quantity > 480){

						$price -= 5.9;

						$price = $price < 0?0:$price;

						$reduce_total = 480 * $price;

						$total -= $reduce_total;

					}

				}elseif($temp_total >= 10000){

					if($quantity <= 800 && $quantity > 0){

						$price -= 5.5;

						$price = $price < 0?0:$price;

						$reduce_total = $quantity * $price;

						$total -= $reduce_total;

					}elseif($quantity > 800){

						$price -= 5.5;

						$price = $price < 0?0:$price;

						$reduce_total = 800 * $price;

						$total -= $reduce_total;

					}

				}

				if($reduce_total != 0){

					$total_data[] = array(
						'code'       => 'slippers',
						'title'      => '拖鞋优惠',
						'value'      => (0 - $reduce_total),
						'sort_order' => $this->config->get('slippers_sort_order')
					);

				}

			}

		}

	}
}
